package com.g24.partychecker;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Favinfo extends Activity
{
	DBAdapter mDbHelper;
	private long ROWIDN;
	private int MENU_DELETE_EVENT;
	private String naam;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.favinfo);
		
		mDbHelper = new DBAdapter(this);
        mDbHelper.open();
		
		Intent i = getIntent();
		Bundle b = i.getExtras();
		long newID = b.getLong("FEESTID");
		
		Cursor c = mDbHelper.fetchEvent(newID);
        startManagingCursor(c);
        c.moveToFirst();
        
        ROWIDN = c.getLong(0);
        
        naam = c.getString(1);
        System.out.println(naam);
        String subnaam = c.getString(2);
        String genre = c.getString(4);
        String datum = c.getString(5);
        String tijd = c.getString(6);
        String adres = c.getString(7);
        String plaats = c.getString(8);
        String website = c.getString(9);
        String minfo = c.getString(10);
        
        String infostr = "   " + subnaam
							+ "\n Genre:  " + genre
							+ "\n Datum:  " + datum
							+ "\n Tijd:  " + tijd
							+ "\n Adres:  " + adres
							+ "\n Plaats:  " + plaats
							+ "\n Website:  " + website;
        
        TextView txtv1 = (TextView) findViewById(R.id.favinfo_txt1);
		txtv1.setText(naam);
		TextView txtv2 = (TextView) findViewById(R.id.favinfo_txt2);
		txtv2.setText(infostr);
		TextView txtv3 = (TextView) findViewById(R.id.favinfo_txt3);
		txtv3.setText(minfo);
		
		Button meerinfo = (Button) findViewById(R.id.Button_mi);
        meerinfo.setOnClickListener(new View.OnClickListener() 
        {
           public void onClick(View arg0) 
           {
        	   Intent i = new  Intent();
	    		i.putExtra("FEESTID", naam);
	    		i.setClassName("com.g24.partychecker", "com.g24.partychecker.Feestinfo");
	    		
	            startActivity(i);
           }
        });
		
		//mDbHelper.close();
	}
	
	/* Creates the menu items */
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        menu.add(0, MENU_DELETE_EVENT, 0, "Feest verwijderen").setIcon(R.drawable.ic_menu_close);
        return true;
    }

    /* Handles item selections */
    public boolean onOptionsItemSelected(MenuItem item) 
    {
    	if(item.getItemId() == MENU_DELETE_EVENT) 
        {
    		deleteOne();
			return true;
        }
        return false;
    }

	private void deleteOne() 
	{
		mDbHelper.deleteEvent(ROWIDN);
		
		Context context = getApplicationContext();
 	   	CharSequence text = naam + " verwijderd";
 	   	int duration = Toast.LENGTH_SHORT;
 	   	Toast toast = Toast.makeText(context, text, duration);
 	   	toast.show();
 	   	Toast.makeText(context, text, duration).show();
		
		Intent z = new Intent(Favinfo.this, Hoofdscherm.class);
        startActivity(z);
	}
}